package sz;

import service.BusinessService;
import service.impl.BusinessServiceImpl;

import java.lang.reflect.Proxy;

public class JdkProxyExample {
    public static void main(String[] args) {
        // 创建业务对象
        BusinessService businessService = new BusinessServiceImpl();
        // 创建调用处理器
        LogInvocationHandler handler = new LogInvocationHandler(businessService);
        // 创建代理对象
        BusinessService proxy = (BusinessService) Proxy.newProxyInstance(
                BusinessService.class.getClassLoader(),
                new Class<?>[]{BusinessService.class},
                handler
        );
        // 调用代理对象的方法
        proxy.doBusiness();
    }
}
